package com.zcl.Thread.t2;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/3/9  16:32
 */



class Ticket extends Thread {
    private static int ticket = 100;

    @Override
    synchronized public void run() {
        while (true){
            if (ticket > 0) {
                System.out.println(getName()+ ": 卖票,票号为: "+ ticket);
                ticket--;
            }else {
                break;
            }
        }
    }
}

public class TestTicket {

    public static void main(String[] args) {
        Ticket ticket1 = new Ticket();
        Ticket ticket2 = new Ticket();
        Ticket ticket3 = new Ticket();
        ticket1.setName("窗口1");
        ticket2.setName("窗口2");
        ticket3.setName("窗口3");

        ticket1.start();
        ticket2.start();
        ticket3.start();
    }


}
